﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MagicArenaFramework.GameObject.Attributes.Concrete
{
    public class CurHealthAttribute : ScalarAttribute
    {
        public const UInt32 CurHealthFamily=0;
        private int Max, Cur;

        public CurHealthAttribute(int maxHealth, int curHealth) : base(CurHealthFamily, curHealth)
        {
            Max = maxHealth;
            Cur = curHealth;
        }

        void MyUpdate()
        {
            if (Cur > Max) Cur = Max;
            if (Cur < 0) die();
            ScalarAttributeHolder p = (Parent as ScalarAttributeHolder);
            // Check for health regen rate here
            //p.ValueFor
        }

        void die()
        {
            //TODO do something when you die, this should probably be handled elsewhere come to think of it...
        }
    }

    public class MaxHealthAttribute : ScalarAttribute
    {
        public const UInt32 MaxHealthFamily=1;
        public MaxHealthAttribute(int maxHealth) : base(MaxHealthFamily, maxHealth) { }
    }

    public class RegenHealthAttribute : ScalarAttribute
    {
        public const UInt32 RegenHealthFamily=2;
        public RegenHealthAttribute(float regenPerSec) : base(RegenHealthFamily, regenPerSec)
        {
            this.UpdateDel = MyUpdate; 
        }

        void MyUpdate(float dt)
        {
            ScalarAttributeHolder holder = (Parent as ScalarAttributeHolder);
            float health;
            float regen;
            if (holder.ValueFor(CurHealthAttribute.CurHealthFamily, out health) && holder.ValueFor(RegenHealthFamily, out regen))
            {
                health += regen * dt;
                holder.AddUpdateValue(CurHealthAttribute.CurHealthFamily, health);
            }
        }
    }
}

